import './style/navbar.less'
import React from "react"
import { Link } from 'react-router-dom'
import { Menu } from "antd"
import { navbarData } from '../config/home';
const { SubMenu, Item } = Menu

export default function ({ current }) {
    return <div className='m-navbar'>
        <div className="container">
            <Menu mode="horizontal" selectedKeys={[current]}>{navbarData.map(item => {
                if (item.children) {
                    return <SubMenu key={item.text} title={item.text}>
                        {item.children.map(subMenu =>
                            <Menu.Item key={subMenu.key || subMenu.text}>
                                {subMenu.link.startsWith('http')
                                    ? <a href={subMenu.link} target={'_blank'}>{subMenu.text}</a>
                                    : <Link to={subMenu.link} >{subMenu.text}</Link>
                                }
                            </Menu.Item>
                        )}
                    </SubMenu>
                }
                return <Item key={item.key || item.text}>
                    {item.link.startsWith('http')
                        ? <a href={item.link} target={'_blank'}>{item.text}</a>
                        : <Link to={item.link} >{item.text}</Link>
                    }

                </Item>
            })}</Menu>
        </div>
    </div>
}